package com.aaa.shuke2024.controller;

import com.aaa.shuke2024.entity.AlarmHistory;
import com.aaa.shuke2024.service.AlarmHistoryService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 历史告警信息(AlarmHistory)表控制层
 *
 * @author teacherChen
 * @since 2024-12-04 16:10:58
 */
@RestController
@RequestMapping("alarmHistory")
public class AlarmHistoryController {
    /**
     * 服务对象
     */
    @Resource
    private AlarmHistoryService alarmHistoryService;

    /**
     * 分页查询
     *
     * @param alarmHistory 筛选条件
     * @param page      分页对象
     * @param limit      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<AlarmHistory>> queryByPage(AlarmHistory alarmHistory,int page, int limit) {
        PageRequest pageRequest = PageRequest.of(page-1, limit);
        return ResponseEntity.ok(this.alarmHistoryService.queryByPage(alarmHistory, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<AlarmHistory> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.alarmHistoryService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param alarmHistory 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<AlarmHistory> add(AlarmHistory alarmHistory) {
        return ResponseEntity.ok(this.alarmHistoryService.insert(alarmHistory));
    }

    /**
     * 编辑数据
     *
     * @param alarmHistory 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<AlarmHistory> edit(AlarmHistory alarmHistory) {
        return ResponseEntity.ok(this.alarmHistoryService.update(alarmHistory));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.alarmHistoryService.deleteById(id));
    }

}

